﻿using System;
using System.Collections.Generic;
using System.Text;

namespace BBMS.DLL.DataContract
{
    public class CTyThuHo : BBMS.DLL.Base.ObjectBase
    {
        public string Ma;
        public string Ten;
        public string DienThoai;
        public string DiaChi;

        public CTyThuHo() 
        {
        }
        
        public CTyThuHo(string ma, string ten, string diachi, string dienthoai)
        {
            this.Ma = ma;
            this.Ten = ten;
            this.DiaChi = diachi;
            this.DienThoai = dienthoai;
        }

        public override object Key
        {
            get
            {
                return this.Ma;
            }
        }
        public override string Name
        {
            get
            {
                return this.Ten;
            }
        }
        public override string  TableName
        {
	        get 
	        {
                return "company";
	        }
        }
        
        public override string[] KeyFields
        {
            get
            {
                return new string[] { "Ma" };
            }
        }

        public override string[] IDFields
        {
            get
            {
                return new string[] { "Ma" };
            }
        }

        public override bool CanDelete(MySql.Data.MySqlClient.MySqlCommand cmd, System.Data.DataRow row)
        {
            return true;
        }

        public override System.Data.DataTable GetObjectDataTable()
        {
            System.Data.DataTable dt = new System.Data.DataTable("congtythuho");
            dt.Columns.Add("Ma", typeof(String));
            dt.Columns.Add("Ten", typeof(String));
            dt.Columns.Add("DiaChi", typeof(String));
            dt.Columns.Add("DienThoai", typeof(String));
            return dt;
        }
        public override System.Data.DataRow ObjectToDataRow()
        {
            System.Data.DataRow row = this.GetObjectDataTable().NewRow();
            row["Ma"] = this.Ma;
            row["Ten"] = this.Ten;
            row["DiaChi"] = this.DiaChi;
            row["DienThoai"] = this.DienThoai;
            return row;
        }

        public override BBMS.DLL.Base.ObjectBase DataRowToObject(System.Data.DataRow row)
        {
            CTyThuHo obj = null;
            try
            {
                obj = new CTyThuHo(row["Ma"].ToString(), row["Ten"].ToString(), row["DiaChi"].ToString(), row["DienThoai"].ToString());
            }
            catch { }
            return obj;
        }

        public override BBMS.DLL.Base.ObjectBase DataReaderToObject(MySql.Data.MySqlClient.MySqlDataReader rd)
        {
            CTyThuHo obj = null;
            try
            {
                obj = new CTyThuHo(rd["Ma"].ToString(), rd["Ten"].ToString(), 
                    rd["DiaChi"].ToString(), rd["DienThoai"].ToString());
            }
            catch { }
            return obj;
        }
        public override string InsertNew()
        {
            string str = base.InsertNew();
            if (str == "") ObjectLists.CTyThuHoList.Add(this);
            return str;
        }
        public override string Delete()
        {
            string str = base.Delete();
            if (str == "") ObjectLists.CTyThuHoList.Remove(this);
            return str;
        }
        public override string Save()
        {
            string str = base.Save();
            if (str == "") ObjectLists.CTyThuHoList.Update(this);
            return str;
        }
    }
}
